<?php

namespace App\Repositories;

use App\Models\CarBrand;
use BobCoder\Construct\Foundation\Repository\Repository;

class CarBrandRepository extends Repository
{
    protected $model;

    public function __construct()
    {
        $this->model = new CarBrand();
    }


    /**
     * 车辆品牌列表
     * @param string $name 品牌名称
     * @param array $columns
     * @return mixed
     * @Author 姿势就是力量
     */
    public function getList(string $name, array $columns = ['*'])
    {
        return $this->model
            ->select($columns)
            ->when($name, function ($query) use ($name) {
                $query->where('name', 'like', '%' . $name . '%');
            })->orderBy('sort', 'desc')
            ->pagination()
            ->get();
    }

}
